﻿
import QtQuick 2.15
import FluentUI 1.0

FluObject{
    property var navigationView
    property var paneItemMenu

    function rename(item, newName){
        if(newName && newName.trim().length>0){
            item.title = newName;
        }
    }
    FluPaneItem{
        id: item_text
        title: qsTr("连接")
        icon: FluentIcons.Home
        count: 0
        infoBadge: FluBadge{
            count: item_text.count
            color: Qt.rgba(82/255,196/255,26/255,1)
        }
        url: "qrc:/CommLinkPage.qml"
        onTap: {
            item_text.count = 0
            navigationView.push(url)
        }
    }
    FluPaneItem{
        id: home_item
        title: qsTr("线温配置界面")
        icon: FluentIcons.Settings
        count: 0
        infoBadge: FluBadge{
            count: item_text.count
            color: Qt.rgba(82/255,196/255,26/255,1)
        }
        url:"qrc:/LineTempPage.qml"
        onTap: {
            item_text.count = 0
            navigationView.push(url)
        }
    }
    FluPaneItem{
        id: settings_item
        title: qsTr("接地极配置界面")
        icon: FluentIcons.BulletedListMirrored
        count: 0
        infoBadge: FluBadge{
            count: item_text.count
            color: Qt.rgba(82/255,196/255,26/255,1)
        }
        url:"qrc:/GroundedPage.qml"
        onTap: {
            item_text.count = 0
            navigationView.push(url)
        }
    }
    function getRecentlyAddedData(){
        var arr = []
        var items = navigationView.getItems();
        for(var i=0;i<items.length;i++){
            var item = items[i]
            if(item instanceof FluPaneItem && item.extra && item.extra.recentlyAdded){
                arr.push(item)
            }
        }
        arr.sort(function(o1,o2){ return o2.extra.order-o1.extra.order })
        return arr
    }

    function getRecentlyUpdatedData(){
        var arr = []
        var items = navigationView.getItems();
        for(var i=0;i<items.length;i++){
            var item = items[i]
            if(item instanceof FluPaneItem && item.extra && item.extra.recentlyUpdated){
                arr.push(item)
            }
        }
        return arr
    }

    function getSearchData(){
        if(!navigationView){
            return
        }
        var arr = []
        var items = navigationView.getItems();
        for(var i=0;i<items.length;i++){
            var item = items[i]
            if(item instanceof FluPaneItem){
                if (item.parent instanceof FluPaneItemExpander)
                {
                    arr.push({title:`${item.parent.title} -> ${item.title}`,key:item.key})
                }
                else
                    arr.push({title:item.title,key:item.key})
            }
        }
        return arr
    }

    function startPageByItem(data){
        navigationView.startPageByItem(data)
    }

}
